﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.Collections.Specialized;

namespace PasswordProvider.ViewModel.Framework
{
    /// <summary>
    /// ListEditViewModel: Encapsulates the data for editing a list of objects.
    /// Inherits from VisualViewModel and adds the List property.
    /// </summary>
    public class ListEditViewModel<T> : VisualViewModel
    {
        internal ListEditViewModel()
            : base() 
        { }
        internal ListEditViewModel(string displayName, string toolTip, IEnumerable<T> list)
            : base(displayName, toolTip)
        {
            if (list != null)
            {
                _list = new ObservableCollection<T>(list);
                _list.CollectionChanged += delegate { OnPropertyChanged("List"); };
            }
        }

        /// <summary>
        /// Property List. Returns an ObservableCollection.
        /// </summary>
        public ObservableCollection<T> List
        {
            get
            {
                if (_list == null)
                {
                    _list = new ObservableCollection<T>();
                    _list.CollectionChanged += delegate { OnPropertyChanged("List"); };
                }
                return _list;
            }
        } private ObservableCollection<T> _list;

    }
}
